<?php
/**
 * 头部菜单
 * User: adophper <hello@adophper.com>
 * Date: 2018/3/22
 * Time: 11:43
 */
namespace frontend\widgets;
use common\services\FrontendMenuServices;
use yii\bootstrap\Widget;

class FootMenu extends Widget {

    private $view = '@frontend/views/widget/foot-menu.php';

    public $params = [];

    public function init()
    {
        $menuService = new FrontendMenuServices();
        $footMenu = $menuService->getMenu('foot');
        $data = [];
        if (!empty($footMenu)) {
            foreach ($footMenu as $k =>$v){
                if($v['parent_id'] == 0){
                    $v['child'] = [];
                    foreach ($footMenu as $val){
                        if($val['parent_id'] == $v['id']){
                            array_push($v['child'],$val);
                        }
                    }
                    $data[$k]= $v;
                }
            }
        }
        $this->params['menu'] = $data;
    }

    public function run()
    {
        echo $this->renderFile($this->view, $this->params);
    }
}